home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Developer University / DUProjects / Talker / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  6.6 KB  |  247 lines  |  [TEXT/CWIE]

  1. //    Release Version:    $ ODF 1 $
  2. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. //=======================================================================
  5. #ifndef PART_H
  6. #include "Part.h"
  7. #endif
  8.  
  9. #ifndef CONTENT_H
  10. #include "Content.h"
  11. #endif
  12.  
  13. #ifndef FRAME_H
  14. #include "Frame.h"
  15. #endif
  16.  
  17. #ifndef COMMANDS_H
  18. #include "Commands.h"
  19. #endif
  20.  
  21. #ifndef DEFINES_K
  22. #include "Defines.k"            // command numbers
  23. #endif
  24.  
  25. // ----- Framework Layer -----
  26. #ifndef FWCONTXT_H
  27. #include "FWContxt.h"            // FW_CViewContext
  28. #endif
  29.  
  30. #ifndef FWABOUT_H
  31. #include "FWAbout.h"            //::FW_About()
  32. #endif
  33.  
  34. #include "FWClpCmd.h"            // FW_CClipboardCommand
  35.  
  36. // ----- OS Layer -----
  37. #ifndef FWCFMRES_H
  38. #include "FWCFMRes.h"            // FW_CSharedLibraryResourceFile, FW_gInstance
  39. #endif
  40.  
  41. #ifndef FWMENU_H
  42. #include "FWMenu.h"                // FW_CMenuBar, etc.
  43. #endif
  44.  
  45. #ifndef FWEVENT_H
  46. #include "FWEvent.h"            // FW_CMenuEvent, FW_CMouseEvent
  47. #endif
  48.  
  49. #ifndef FWRECSHP_H
  50. #include "FWRecShp.h"            // FW_CRectShape
  51. #endif
  52.  
  53. #ifndef FWPICSHP_H
  54. #include "FWPicShp.h"            // FW_PPicture, FW_CPictureShape
  55. #endif
  56.  
  57. #ifndef FWRRCSHP_H
  58. #include "FWRRcShp.h"            // FW_CRoundRectShape
  59. #endif
  60.  
  61. #ifndef FWCMD_H
  62. #include "FWCmd.h"                // FW_CCommand
  63. #endif
  64.  
  65. #ifndef FWDRCMD_H
  66. #include "FWDrCmd.h"
  67. #endif
  68.  
  69. // ----- OpenDoc Includes -----
  70. #ifndef SOM_ODDragItemIterator_xh
  71. #include <DgItmIt.xh>            // ODDragItemIterator
  72. #endif
  73.  
  74. #ifndef SOM_ODTranslation_xh    
  75. #include <Translt.xh>            // ODTranslation    
  76. #endif
  77.  
  78. #ifndef SOM_ODSession_xh
  79. #include <ODSessn.xh>            // ODSession
  80. #endif
  81.  
  82. #ifndef SOM_Module_OpenDoc_StdProps_defined
  83. #include <StdProps.xh>            // kODPropContents
  84. #endif
  85.  
  86. //========================================================================================
  87. #ifdef FW_BUILD_MAC
  88. #pragma segment Talker
  89. #endif
  90.  
  91. FW_DEFINE_AUTO(CTalkerFrame)
  92.  
  93. //========================================================================================
  94. CTalkerFrame::CTalkerFrame(Environment* ev, ODFrame* odFrame, 
  95.                                     FW_CPresentation* presentation, CTalkerContent* content)
  96.   : FW_CFrame(ev, odFrame, presentation, content->GetPart(ev)),
  97.     FW_MDroppableFrame(ev, this),    
  98.     fTalkerContent(content),
  99.     fPictShape(NULL)
  100. {
  101.     this->MyInitPicture(ev);
  102.     FW_END_CONSTRUCTOR
  103. }
  104.  
  105. //----------------------------------------------------------------------------------------
  106. void
  107. CTalkerFrame::MyInitPicture(Environment* ev)
  108. {
  109.     FW_CSharedLibraryResourceFile resFile(ev);            // PICT resource in shared library
  110.     const short kPizzaPictID = 2000;
  111.     FW_CPicture picture(resFile, kPizzaPictID);
  112.     fFrameRect = this->GetBounds(ev);        // Get new Frame Rect
  113.     fPictShape = FW_NEW(FW_CPictureShape, (picture, fFrameRect));
  114. }
  115.  
  116. //----------------------------------------------------------------------------------------
  117. CTalkerFrame::~CTalkerFrame()
  118. {
  119.     FW_START_DESTRUCTOR
  120.     delete fPictShape;
  121. }
  122.  
  123. //----------------------------------------------------------------------------------------
  124. void 
  125. CTalkerFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  126. {
  127.     FW_CViewContext context(ev, this, odFacet, invalidShape);
  128.     
  129.     // erse invalid shape
  130.     FW_CRect invalidRect;
  131.     context.GetClipRect(invalidRect);
  132.     FW_CRectShape::RenderRect(context, invalidRect, FW_kFill, FW_kWhiteEraseInk);
  133.     // draw the picture
  134.     fPictShape->Render(context);
  135.     // draw a frame around it
  136.     FW_CRoundRectShape::RenderRoundRect(context,
  137.                                         fFrameRect, 
  138.                                         FW_CPoint(FW_IntToFixed(30), FW_IntToFixed(30)),
  139.                                         FW_kFrame,
  140.                                         FW_CInk(FW_kRGBBlue));
  141. }
  142.  
  143. //----------------------------------------------------------------------------------------
  144. void 
  145. CTalkerFrame::FrameShapeChanged(Environment* ev)
  146. {
  147.     FW_CFrame::FrameShapeChanged(ev);
  148.     fFrameRect = this->GetBounds(ev);    // Get new frame rect
  149.     // modify picture
  150.     FW_CPicture picture = fPictShape->GetPicture();
  151.     fPictShape->SetGeometry(picture, fFrameRect);
  152.     // force redraw of whole frame
  153.     this->Invalidate(ev, fFrameRect);            
  154. }
  155.  
  156. //----------------------------------------------------------------------------------------
  157. FW_Boolean 
  158. CTalkerFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus,
  159.                                                     FW_Boolean isRoot)    // Override
  160. {
  161.     if (hasMenuFocus) {
  162.         FW_Boolean hasRightProperty = FALSE;
  163.         hasRightProperty = this->HasPropertyOnClipboard(ev, kODPropContents, FW_CPart::gMacTEXTDataType);
  164.         menuBar->EnableCommand(ev, kODCommandPaste, hasRightProperty);
  165.         menuBar->EnableCommand(ev, cFasterCmd, TRUE);
  166.         menuBar->EnableCommand(ev, cSlowerCmd, TRUE);
  167.     }
  168.     return FALSE;
  169. }
  170.  
  171. //----------------------------------------------------------------------------------------
  172. FW_Boolean 
  173. CTalkerFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)    // Override
  174. {
  175.     FW_Boolean menuHandled = TRUE;
  176.     CTalkerCommand* cmd = NULL;
  177.     switch (theMenuEvent.GetCommandID(ev)) { 
  178.         case kODCommandAbout:
  179.             ::FW_About(ev, this->GetPart(ev), kAbout);
  180.             break;
  181.  
  182.         case cFasterCmd:         
  183.             cmd = FW_NEW(CTalkerCommand, (ev, cFasterCmd, this, 
  184.                                             fTalkerContent->MyGetTalker()));
  185.             cmd->Execute(ev);
  186.             break;
  187.         
  188.         case cSlowerCmd: 
  189.             cmd = FW_NEW(CTalkerCommand, (ev, cSlowerCmd, this, 
  190.                                             fTalkerContent->MyGetTalker()));
  191.             cmd->Execute(ev);
  192.             break;
  193.  
  194.         default:
  195.             menuHandled = FALSE;
  196.     }
  197.     return menuHandled;
  198. }
  199.  
  200. //----------------------------------------------------------------------------------------
  201. FW_Boolean 
  202. CTalkerFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  203. {    
  204.     FW_UNUSED(ev);
  205.     FW_Boolean handledEvent = FALSE;
  206.     if (theMouseEvent.GetNumberOfClicks(ev) == 2) {
  207.         fTalkerContent->MySayText(ev);
  208.         handledEvent = TRUE;
  209.         }
  210.     return handledEvent;
  211. }
  212.  
  213. //----------------------------------------------------------------------------------------
  214. ODDragResult 
  215. CTalkerFrame::CanAcceptDrop(Environment* ev, ODDragItemIterator* dragInfo)
  216. {
  217.     ODDragResult result = FW_MDroppableFrame::CanAcceptDrop(ev, dragInfo);
  218.     
  219.     if (!result) {
  220.         ODStorageUnit *dragSU;
  221.         for (dragSU = dragInfo->First(ev); dragSU; dragSU = dragInfo->Next(ev))
  222.             if (dragSU->Exists(ev, kODPropContents, FW_CPart::gMacTEXTDataType, 0))    // 'TEXT' in Scrap
  223.                 return TRUE;
  224.     }
  225.     return result;
  226. }
  227.  
  228. //----------------------------------------------------------------------------------------
  229. FW_CDropCommand* 
  230. CTalkerFrame::NewDropCommand(Environment *ev, 
  231.                                     FW_CFrame* frame,
  232.                                     ODDragItemIterator* dropInfo, 
  233.                                     ODFacet* facet, 
  234.                                     const FW_CPoint& dropPoint)
  235. {
  236.     return FW_NEW(FW_CDropCommand, (ev, frame, dropInfo, facet, dropPoint, !FW_kCanUndo) );
  237. }
  238.  
  239. //----------------------------------------------------------------------------------------
  240. FW_CClipboardCommand* 
  241. CTalkerFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  242. {
  243.     return FW_NEW(FW_CClipboardCommand, 
  244.             (ev, commandID, this, ! FW_kCanUndo) );
  245. }
  246.  
  247.